package com.ruoyi.inspection.config;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author He Bo
 * @create 2024/7/10 17:19
 */

@Slf4j
@Component
public class IntegrationConfig {

    private static String ip = "http://dev.intergration.platform.lcap.jl.com/";

    private static String addr = "rest/saveMajorHazard";

    /**
     * 安全包保
     */
    public static final String AQBB = "ZDWX_AQBB";
    /**
     * 重大危险源清单
     */
    public static final String ZDWXQD = "ZDWX_ZDWXQD";
    /**
     * 实时检测
     */
    public static final String SSJC = "ZDWX_SSJC";
    /**
     * 报警信息
     */
    public static final String BJXX = "ZDWX_BJXX";

    public static void push(String reportType, List list) {
        Map<String, Object> map = new HashMap<>(10);
        map.put("appId","1332");
        map.put("reportCompany","石洞口煤气");
        map.put("reportModule","重大危险模块");
        map.put("reportType",reportType);
        map.put("reportDate", DateUtil.now());
        map.put("reportContent", list);
        log.info("提交一体化数据：{}", JSONUtil.toJsonStr(map));

        HttpResponse execute = HttpRequest
                .post(ip + addr)
                .charset("UTF-8")
                .body(JSONUtil.toJsonStr(map))
                .contentType("application/json")
                .timeout(5000)
                .execute();
        int status = execute.getStatus();
        if (status != 200) {
            log.error("请求失败 状态码：{}",status);
            return;
        }
        String body = execute.body();
        log.info("请求返回: {}",body);
        JSONObject jsonObject = JSONUtil.parseObj(body);
        if (jsonObject.getInt("status").equals(1)) {
            log.info("请求成功");
        } else {
            log.error("请求失败");
        }
    }
}
